package com.smartboard.network.server;

import com.smartboard.network.game.IUser;

import java.io.Serializable;

/**
 * Created by cheas on 2018/8/13.
 */

public class User implements IUser, Serializable {
    private static final long serialVersionUID = 3L;

    private int mId;
    private String mName;
    private String mNickName;
    private int mWin = 0;
    private int mLost = 0;
    private int mDraw = 0;
    private int mChessType;
    private int mRoomId = 0;
    private int mGameId = 0;
    private boolean mIsReady = false;

    private User() {

    }

    public User(String name, int chessType) {
        mName = name;
        mChessType = chessType;
        mId = IdsPool.createId(IdsPool.ID_TYPE_USER, mChessType);
        IdsPool.addObject(mId, this);
        mNickName = name;
    }

    public int getId() {
        return mId;
    }

    public String getName() {
        return mName;
    }

    public void setNickName(String name) {
        mNickName = name;
    }

    public String getNickName() {
        return mNickName;
    }

    @Override
    public int getWin() {
        return mWin;
    }

    public void addWin() {
        mWin ++;
    }

    @Override
    public int getLost() {
        return mLost;
    }

    public void addLost() {
        mLost ++;
    }

    @Override
    public int getDraw() {
        return mDraw;
    }

    public void addDraw() {
        mDraw ++;
    }

    @Override
    public int getChessType() {
        return mChessType;
    }

    @Override
    public int getRoomId() {
        return mRoomId;
    }

    public void setRoomId(int id) {
        mRoomId = id;
    }

    @Override
    public int getGameId() {
        return mGameId;
    }

    public void setGameId(int id) {
        mGameId = id;
    }

    public boolean isReady() {
        return mIsReady;
    }

    public void setIsReady(boolean ready) {
        mIsReady = ready;
    }

    public User clone() {
        User newUser = new User();
        newUser.mId = mId;
        newUser.mName = mName;
        newUser.mNickName = mNickName;
        newUser.mWin = mWin;
        newUser.mLost = mLost;
        newUser.mDraw = mDraw;
        newUser.mChessType = mChessType;
        newUser.mRoomId = mRoomId;
        newUser.mGameId = mGameId;
        newUser.mIsReady = mIsReady;
        return newUser;
    }

    @Override
    public boolean equals(Object other) {
        return (other instanceof User) && ((User)other).mName.equals(mName);
    }

    @Override
    public String toString() {
        return "User[name=" + mName + "]";
    }
}
